package com.gupao.vip.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by 17082655 on 2019/1/7.
 */
@RestController
@RequestMapping("/person")
public class PersonRestController {
	//将json转化为properties
	@PostMapping(value = "/jsonToPro",produces = "application/properties+person")
	public Person personJsonToPro(@RequestBody Person person){
		return person;
	}

	//将properties转化为json
	@RequestMapping(value = "/proToJson",produces = MediaType.APPLICATION_JSON_VALUE,consumes = "application/properties+person",
			headers="Referer=http://www.ifeng.com/",method = RequestMethod.GET)
	public Person personProToJson(@RequestBody Person person){
		return person;
	}
	//将properties转化为json
	@GetMapping(value = "/stu")
	public void stu(HttpServletRequest request, HttpServletResponse response)throws Exception{
		/*StringBuffer requestURL = request.getRequestURL();
		System.out.println(requestURL);
		String key = request.getParameter("id");
		System.out.println(key);*/
		Person person = new Person();
		person.setName("melo");
		person.setId("1");
	//	response.setContentType("application/json;charset=utf-8");
		response.setContentType("text/plain;charset=utf-8;");
		response.getWriter().write(person.toString());

	}
}
